/**
 *
 */
moduleLearningMap.service('LanguageService', function (LanguageResource, $rootScope, $interval, $q, ConstantService, $$CambioConfig) {

    this.language = function (value) {
        if (!StringUtils.isNlOrUndOrEmpty(value)) {
            var i18n = ConstantService.getItem('currentLanguage');
            if (i18n && i18n.details) {
                var result = i18n.details[value];
                if (result) {
                    return result;
                } else {
                    value;
                }
            }
        }
        return value;
    }
    //var refreshFn;

    this.loadLanguage = function () {
        if (!ConstantService.getItem('currentLanguage')) {
            LanguageResource.load({locale: navigator.language}, {}, function (result) {
                ConstantService.setItem('currentLanguage', result.data);
            });
        }
        //
        // var locale = navigator.language;
        // if (ConstantService.getItem('currentLanguage')) {
        //     locale = ConstantService.getItem(locale+ '_language');
        // }
        // LanguageResource.load({locale: locale}, {}, function (result) {
        //     ConstantService.setItem(locale + '_language', result.data);
        // });
    };

    this.changeLanguage = function (locale) {
        LanguageResource.load({locale: locale}, {}, function (result) {
            ConstantService.setItem('currentLanguage', result.data);
            window.location.reload();
        });
    };
});